import cv2
import numpy as np
if __name__ == '__main__':
    path = 'work4.jpeg'
    image_np = cv2.imread(path)
    image_np_hsv = cv2.cvtColor(image_np, cv2.COLOR_BGR2HSV)
    blue_low1 = np.array([78, 70, 120])
    blue_high1 = np.array([124, 255, 255])
    mask1 = cv2.inRange(image_np_hsv,blue_low1, blue_high1 )
    # red_low2 = np.array(156, 43, 46)
    # re_high2 = np.array(180, 255, 255)
    # mask2 = cv2.inRange(image_np_hsv, red_low1, re_high1)

    # r_mask = cv2.bitwise_or(mask1, mask1)

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    open_image_np = cv2.morphologyEx(src = mask1, op = cv2.MORPH_OPEN, kernel = kernel)       #  形成一个0和255组成的数组

    for i in range(0, image_np.shape[0]):
        for j in range(0, image_np.shape[1]):
            if open_image_np[i, j] == 255:
                image_np[i, j] = (33, 12, 175)
    # color_image_np = cv2.bitwise_and(image_np, image_np, mask = mask1)

    # cv2.imshow('', color_image_np)
    # print(color_image_np)
    cv2.imshow('', image_np)
    cv2.waitKey(0)
    cv2.imwrite('zuoye4.jpg', image_np)

